package savehalloween;

import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;


/**
 *
 * @author wutzelputz
 */
public abstract class Monster{

    /**
     * @var img the image resource for the sprite
     */
    private Image img;
    /**
     * @var sprite the monsters sprite
     */
    private Sprite sprite;
    /**
     * @var posX Current x-coordinate of the sprite
     */
    private int posX = 50;
    /**
     * @var posY Current y-coordinate of the sprite
     */
    private int posY = 50;
    
    /**
     * the amount of life the monster has left
     */
    private int life = 100;

    public Monster(String imageSource){
        try {
            img = Image.createImage(imageSource);
        } catch (Exception ioex) {
            System.out.println(ioex);
        }

        sprite = new Sprite(img, img.getWidth(), img.getHeight());
        sprite.defineReferencePixel((int)img.getWidth()/2, (int) img.getHeight()/2);
    }
    
    /**
     * 
     * @return The current x-coordinate of the Monster (sprites refpixelposition)
     */
    public int getX(){
        return posX;
    }

    /**
     * 
     * @return The current y-coordinate of the Monster (sprites refpixelposition)
     */
    public int getY(){
        return posY;
    }

    /**
     * sets the x-coordinate of the Monster directly
     * @param x - here it shall be positioned
     * @return fluid interface
     */
    public Monster setX(int x){
        posX = x;
        return this;
    }
    
    /**
     * sets the y-coordinate of the Monster directly
     * @param y - here it shall be positioned
     * @return fluid interface
     */
    public Monster setY(int y){
        posY = y;
        return this;
    }
    
    public int getLife(){
    	return life;
    }
    
    /**
     * paints the Monster on the canvas. Also contains movement logic
     * @param g graphics context
     */
    public void paint(Graphics g){
        // for a first, the monster walks only upside
        posY++;
        sprite.setRefPixelPosition(posX, posY);
        sprite.paint(g);
    }
    
}